﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yuans.BinaryConfig.BlobIO
{
    public class MedeliVelCurveCfgBlobValueIO : BlobValueIO
    {
        public byte[] BlobValue { set; get; }
        public void ImportFile(string fileName)
        {
            if (File.Exists(fileName))
            {
                using (BinaryReader fileReader = new BinaryReader(File.Open(fileName, FileMode.Open)))
                {
                    fileReader.BaseStream.Seek(0x12 , SeekOrigin.Begin); // 0x12:offest of keytype 0:white 1:black
                    byte isWhiteKeyRawByte = fileReader.ReadByte();
                    bool isWhiteKey = (isWhiteKeyRawByte == 1) ? true : false;
                    fileReader.BaseStream.Seek(0x3A, SeekOrigin.Begin); // 0x3A:offest of int32 var point num
                    int pointNum = fileReader.ReadInt32();
                    BlobValue = new byte[pointNum];
                    fileReader.BaseStream.Seek(0x42, SeekOrigin.Begin); // 0x42:offest of point value
                    for(int i=0;i<pointNum;i++)
                    {
                        BlobValue[i] = (byte)fileReader.ReadInt32();
                        fileReader.ReadInt32(); // Dummy read for skipping one int32 var
                    }
                }
            }
        }
        public MedeliVelCurveCfgBlobValueIO(string fileName)
        {
            ImportFile(fileName);
        }
        public void ExportFile(string fileName)
        {
            File.WriteAllBytes(fileName, BlobValue);
        }
    }
}
